<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.data.apidata = {};
vue.data.display_field = {};
vue.data.display_field.user_id = true;
vue.data.display_field.username = true;
vue.data.display_field.balance_basic = true;
vue.data.display_field.balance_other = true;
var submit_after_result = function (that) {
};
function intval(i) {
    var i = parseInt(i, 10);
    if (isNaN(i)) i = 0;
    return i;
}
vue.methods.submit = function () {
    const form = {};
    this.ApiPost('/panel/yun/ntuser/list.php', form).then(function (data) {
        vue.data.apidata = data.data;
        for (var key in vue.data.apidata.ntuserList) {
            const ntuser = vue.data.apidata.ntuserList[key];
            const aBal = ntuser.balance.split(',');
            ntuser.balance = intval(aBal[0]);
            ntuser.balance1 = intval(aBal[1]) + ntuser.balance;
        }
        submit_after_result();
    }, function (data) {
        console.log('reject:', data);
        submit_after_result();
    }).catch(function (reason) {
        console.log('catch:', reason);
        submit_after_result();
    })
};
vue.methods.format_balance = function (cpuseconds) {
    return (Math.floor(cpuseconds / 100) / 100) + '元';
};
vue.mounted = function () {
    vue.methods.submit();
};
</script><?php }?>

<div class="row">
    <div class="col-xs-12 col-sm-8 col-md-6 col-lg-6">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">我的远程账号</h3>
                <div class="pull-right">
                    <a class="btn btn-primary btn-xs" type="button" target="_parent" href="/panel.html#/panel/index.html">返回首页</a>
                    <a class="btn btn-primary btn-xs" type="button" target="_parent" href="/panel.html#/panel/yun-nthostlist.html">选购主机</a>
                </div>
            </div>

            <div v-if="apidata.ntuserList">
                <div style="padding-left: 20px;">
                    显示列：
                    <label><input v-model="display_field.username" type="checkbox" />用户名</label>
                    <label><input v-model="display_field.balance_basic" type="checkbox" />现金账户</label>
                    <label><input v-model="display_field.balance_other" type="checkbox" />其他余额</label>
                </div>
                <div v-if="apidata.ntuserList.length>0">
                    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                            <tr role="row">
                                <th v-if="display_field.username">用户名</th>
                                <th v-if="display_field.balance_basic">现金账户</th>
                                <th v-if="display_field.balance_other">其他余额</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr role="row" class="odd" v-for="row in apidata.ntuserList">
                              <td v-if="display_field.username">{{row['username']}}</td>
                              <td v-if="display_field.balance_basic">{{format_balance(row['balance_basic'])}}</td>
                              <td v-if="display_field.balance_other">{{format_balance(row['balance_other'])}}</td>
                              <td>-</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div v-else style="text-align:center">
                    您尚未添加过任何【远程桌面账号】，请先添加。
                </div>
            </div>
            <div v-else style="text-align:center">
                <h3>数据载入中，请稍候...</h3>
            </div>
        </div>
    </div>
</div>
